package com.fjzx.androidframe.base.annotation.injector;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fjzx.androidframe.base.annotation.ItemView;


/**
 * {@link ItemView} 注解注入器
 *
 * @author xiongyongcong
 */
public class ItemViewInjector {
    public static <T> int inject(T t) {
        Class<?> clazz = t.getClass();
        if (clazz.isAnnotationPresent(ItemView.class)) {
            ItemView itemView = clazz.getAnnotation(ItemView.class);
            return itemView.value();
        }
        return 0;
    }

    public static <T> View inject(T t, ViewGroup parent) {
        Class<?> clazz = t.getClass();
        if (clazz.isAnnotationPresent(ItemView.class)) {
            ItemView itemView = clazz.getAnnotation(ItemView.class);
            return LayoutInflater.from(parent.getContext()).inflate(itemView.value(), parent, false);
        }
        return null;
    }
}
